package com.bwie.controller;

import com.bwie.pojo.TbProd;
import com.bwie.pojo.TbProdAtta;
import com.bwie.service.TbProdService;
import com.bwie.utils.Result;
import com.bwie.vo.PageInfoVo;
import com.bwie.vo.ProdPageVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.util.List;

@RestController
@RequestMapping("/shop/prod")
public class ProdController {
    @Autowired
    TbProdService tbProdService;

    /**
     * 获取商品列表
     *
     * @param
     * @return
     */
    @PostMapping("/getProdList")
    public Result getProdList(@RequestBody @Validated ProdPageVo prodPageVo) {
        return tbProdService.getProdList(prodPageVo);
    }

    /**
     * 添加
     *
     * @param tbProd
     * @return
     */
    @PostMapping("/addProd")
    public Result addProd(@RequestBody TbProd tbProd) {
        return tbProdService.addProd(tbProd);
    }


    /**
     * 图片上传
     *
     * @param file
     * @return
     */
    @PostMapping("/uploadFile")
    public Result uploadFile(@RequestPart("file") MultipartFile file) {
        return tbProdService.uploadFile(file);
    }

    /**
     * 添加商品附件
     *
     * @param tbProdAtta
     * @return
     */
    @PostMapping("/addProdAtta")
    public Result addProdAtta(@RequestBody TbProdAtta tbProdAtta) {
        return tbProdService.addProdAtta(tbProdAtta);
    }

    /**
     * 批量删除
     *
     * @param ids
     * @return
     */
    @PostMapping("/deleteBatchProd")
    public Result deleteBatchProd(@RequestBody List<Integer> ids) {
        return tbProdService.deleteBatchProd(ids);
    }

    /**
     * 单个删除
     *
     * @param prodId
     * @return
     */
    @PostMapping("/deleteProd/{prodId}")
    public Result deleteProd(@PathVariable("prodId") Integer prodId) {
        return tbProdService.deleteProd(prodId);
    }
}
